package com.example.reagent_management.ui.history;

import com.chad.library.BR;
import com.example.lib_base.adapter.BasePagingAdapter;
import com.example.lib_base.base.BaseDBFragment;
import com.example.lib_base.base.DataBindingConfig;
import com.example.reagent_management.R;
import com.example.reagent_management.ui.history.adapter.HistoryAdapter;
import com.example.reagent_management.ui.operatedialog.dialogs.BottomHistoryFragment;
import com.google.android.material.animation.AnimationUtils;

import javax.inject.Inject;

import androidx.lifecycle.ViewModelProvider;
import dagger.hilt.android.AndroidEntryPoint;

@AndroidEntryPoint
public class HistoryFragment extends BaseDBFragment {

    private HistoryViewModel mState;
    private HistoryAdapter adapter;

    @Override
    protected void initViewModel() {
        mState = getFragmentScopeViewModel(HistoryViewModel.class);
    }

    @Override
    protected void initViewOrObserve() {
        mState.historyList().observe(this, data -> {
            adapter.submitData(getLifecycle(),data);
        });
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        adapter = new HistoryAdapter();
        adapter.setOnItemClick(data -> {
            BottomHistoryFragment bottomHistoryFragment = new BottomHistoryFragment();
            bottomHistoryFragment.show(getChildFragmentManager(),"BottomHistoryFragment");
            bottomHistoryFragment.updateData(data);
        });
        return new DataBindingConfig(R.layout.fragment_history)
                .addBindingParam(BR.title, "操作记录")
                .addBindingParam(BR.adapter, adapter);
    }
}
